home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE22 / EX11.C < prev    next >
C/C++ Source or Header  |  1995-05-29  |  3KB  |  66 lines

  1. #include <genstub.c>
  2.  
  3. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4. {
  5.    switch (uMsg)
  6.    {
  7.          case WM_COMMAND:
  8.                switch ( LOWORD( wParam ) )
  9.                {
  10.                      case IDM_TEST:
  11.                      {
  12.                            TCHAR szBuffer[128];
  13.                            TCHAR szDateBuffer[128];
  14.                            TCHAR sLongDateFormat[65];
  15.                            HDC   hDC = GetDC( hWnd );
  16.  
  17.                            // Save long date format.
  18.                            GetLocaleInfo( LOCALE_USER_DEFAULT, DATE_LONGDATE,
  19.                                           sLongDateFormat, 64 );
  20.  
  21.                            // Show date and time.
  22.                            GetDateFormat( LOCALE_USER_DEFAULT,
  23.                                           DATE_SHORTDATE,
  24.                                           NULL, NULL, szDateBuffer, 127 );
  25.                            TextOut( hDC, 0, 0, szBuffer, wsprintf( szBuffer,
  26.                                     "The date is %s", szDateBuffer ) );
  27.                            GetDateFormat( LOCALE_USER_DEFAULT, DATE_LONGDATE,
  28.                                           NULL, NULL, szDateBuffer, 127 );
  29.                            TextOut( hDC, 0, 20, szBuffer, wsprintf( szBuffer,
  30.                                     "The long date is %s", szDateBuffer ) );
  31.                            GetTimeFormat( LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT,
  32.                                           NULL, NULL, szDateBuffer, 127 );
  33.                            TextOut(hDC, 0, 40, szBuffer, wsprintf( szBuffer,
  34.                                    "The time is %s", szDateBuffer ) );
  35.  
  36.                            // Change long date format.
  37.                            memcpy( szBuffer,
  38.                                    "dd\0\" of \"\0MMM\0\" of \"\0YYYY\0\0", 27 );
  39.                            SetLocaleInfo( LOCALE_USER_DEFAULT, DATE_LONGDATE,
  40.                                           szBuffer );
  41.  
  42.                            // Get formatted date in new locale format.
  43.                            GetDateFormat( LOCALE_USER_DEFAULT, DATE_LONGDATE,
  44.                                           NULL, NULL, szDateBuffer, 127 );
  45.                            TextOut( hDC, 0, 60, szBuffer, wsprintf( szBuffer,
  46.                                     "The long date is %s", szDateBuffer ));
  47.                            ReleaseDC( hWnd, hDC );
  48.  
  49.                            // Restore long date format.
  50.                            SetLocaleInfo( LOCALE_USER_DEFAULT,
  51.                                           DATE_LONGDATE, sLongDateFormat );
  52.                      }
  53.                      break;
  54.                      case IDM_EXIT:
  55.                            DestroyWindow( hWnd );
  56.                      break;
  57.                }
  58.                break;
  59.          case WM_DESTROY:
  60.                PostQuitMessage( 0 );
  61.                break;
  62.          default:
  63.                return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  64.    }
  65.    return( NULL );
  66. }